<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String categoryId = (String)request.getAttribute("categoryId");
	String id = (String)request.getAttribute("id");
	String type = (String)request.getAttribute("type");
	
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>新增机构</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<script type="text/javascript" src="<%=basePath%>ckeditor/ckeditor.js"></script>
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/page/head.jsp"></jsp:include>
<script type="text/javascript">
		//打开页面判断操作类型是否为edit，为edit则在加载事件根据url参数中传递过来的webPageId查找出当前用户的信息作出修改
		var uId = "<%=id%>";
		var categoryId = "<%=categoryId%>";
		var type = "<%=type%>";
	
		//保存信息
		function save(){
			var types = escape(escape($('#type').val()));    //获取type值
			var entityId = escape(escape($('#entityId').val()));					//获取entityId值
			var entityName = escape(escape($('#entityName').val()));    		//获取entityName值
			var entityUrl = escape(escape($('#entityUrl').val()));				//获取entityUrl值
			var imageUrl1 = escape(escape($('#imageUrl1').val()));   //获取url值
			var imageUrl2 = escape(escape($('#imageUrl2').val()));    //获取otherUrl值
			
			if($('#fm').form('validate')){
				//做操作类型判断
			
				var urlPath = "";
				if(type == "add"){
					//add处理路径
					urlPath = path +"/webPage/save.do?categoryId="+categoryId+"&types="+types+"&entityId="+entityId+"&entityName="+entityName+"&entityUrl="+entityUrl+"&imageUrl1="+imageUrl1+"&imageUrl2="+imageUrl2;
				}else{
					//update处理
					urlPath = path +"/webPage/update.do?categoryId="+categoryId+"&types="+types+"&entityId="+entityId+"&entityName="+entityName+"&entityUrl="+entityUrl+"&imageUrl1="+imageUrl1+"&imageUrl2="+imageUrl2;
					urlPath += "&id="+uId;
				}
			
				$.ajax({
					  url:urlPath,
					  success: function() {
						  window.location = path+"/webPage/webPageDetailMgr.do?categoryId="+categoryId;
					  }
					});
			}
		}
		
		//撤销回退
		function callback(){
			window.location = path+"/webPage/webPageDetailMgr.do?categoryId="+categoryId;
		}
		

		function selectImage1(){
			var w =(screen.width-300)/2;
			var h = (screen.height-60)/2;
			var ret = window.showModalDialog(path+"/page/common/image-upload.jsp",window,"dialogWidth:300px;dialogHeight:60px;dialogTop:"+h+"px;dialogLeft:"+w+"px;help:no;status:no;center:yes");
			if(ret != null){
				$('#image1').attr('src',path+"/"+ret[0][0]);
				$('#imageUrl1').attr('value',ret[0][0]);
			}
		}
		function selectImage2(){
			var w =(screen.width-300)/2;
			var h = (screen.height-60)/2;
			var ret = window.showModalDialog(path+"/page/common/image-upload.jsp",window,"dialogWidth:300px;dialogHeight:60px;dialogTop:"+h+"px;dialogLeft:"+w+"px;help:no;status:no;center:yes");
			if(ret != null){
				$('#image2').attr('src',path+"/"+ret[0][0]);
				$('#imageUrl2').attr('value',ret[0][0]);
			}
		}
	</script>
	
</head>

<body>
	<div class="right">
		<h1>
			<b>${type=="add"?"添加":"编辑"}商品</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span>
		</h1>
		<div class="ri_main">
		
				<table width="100%" border="0" cellspacing="1" cellpadding="8"
					style="background: #d9d9d9;">
					<tr>
						<td align="right" bgcolor="#FFFFFF">类型</td>
						<td bgcolor="#FFFFFF" align="left" >
						<select id="type" name="type">
								<c:forEach var="types" items="${types}">
						   			<c:choose>
						   				<c:when test="${webPageDetail != null && types.code == webPageDetail.categoryId}">
						  					<option value="${types.code}" selected="selected">${types.name}</option>
						   				</c:when>
						   				<c:otherwise>
						   					<option value="${types.code}">${types.name}</option>
						   				</c:otherwise>
						   			</c:choose>
						   		</c:forEach>
						  </select>
						
						<td width="15%" align="right" bgcolor="#FFFFFF">编号</td>
						<td bgcolor="#FFFFFF"  align="left" width="35%"><label
							for="textfield"></label> 
						<input
							id="entityId" name="entityId" class="easyui-validatebox" required="true"
							style="width: 150px;" value="${webPageDetail != null?webPageDetail.entityId:''}">
						</td>
					</tr>
					<tr>
						<td width="15%" align="right" bgcolor="#FFFFFF">名称</td>
						<td bgcolor="#FFFFFF"  align="left" width="35%" colspan="3"><label
							for="textfield"></label> 
						<input
							id="entityName" name="entityName" class="easyui-validatebox" required="true"
							style="width: 150px;" value="${webPageDetail != null?webPageDetail.entityName:''}">
						</td>
					</tr>
					<tr>
						<td width="15%" align="right" bgcolor="#FFFFFF">链接地址</td>
						<td bgcolor="#FFFFFF"  align="left" width="35%" colspan="3"><label
							for="textfield"></label> 
						<input
							id="entityUrl" name="entityUrl" class="easyui-validatebox" 
							style="width: 150px;" value="${webPageDetail != null?webPageDetail.entityUrl:''}">
						</td>
					</tr>
					<tr>
						<td align="right" bgcolor="#FFFFFF">图片1</td>
						<td bgcolor="#FFFFFF" colspan="3"><img id="image1" width="200"
							height="200" name="image1"
							src="<%=basePath %>${webPageDetail != null?webPageDetail.imageUrl1:''}"></img>
							<input type="hidden" id="imageUrl1" name="imageUrl1"
							value="${webPageDetail != null?webPageDetail.imageUrl1:''}">
							<input type="button" onclick="selectImage1()" value="选择" /></td>
					</tr>
					
					<tr>
						<td align="right" bgcolor="#FFFFFF">图片2</td>
						<td bgcolor="#FFFFFF" colspan="3"><img id="image2" width="200"
							height="200" name="image2"
							src="<%=basePath %>${webPageDetail != null?webPageDetail.imageUrl2:''}"></img>
							<input type="hidden" id="imageUrl2" name="imageUrl2"
							value="${webPageDetail != null?webPageDetail.imageUrl2:''}">
							<input type="button" onclick="selectImage2()" value="选择" /></td>
					</tr>
					<tr>
						<td bgcolor="#FFFFFF" colspan="4" align="center"><a
							href="javascript:void(0);" class="easyui-linkbutton"
							iconCls="icon-ok" onclick="save()">保存</a> <a
							href="javascript:void(0);" class="easyui-linkbutton"
							iconCls="icon-cancel" onclick="callback()">取消</a>
						</td>
					</tr>
					
				</table>
			
		</div>
	</div>
</body>
</html>
